package com.eurake.seckill.utils;

import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {
    public static String md5(String str) {
        return DigestUtils.md5Hex(str);
    }

    private static final String salt = "1a2b3c";

    public static String inputPassToTransPass(String inputPass){
        // 加入盐进行混淆
        String str = ""+salt.charAt(0)+salt.charAt(2)+inputPass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }
    public static String transPassToDBPass(String inputPass,String dbSalt){
        String str = ""+dbSalt.charAt(0)+dbSalt.charAt(2)+inputPass+dbSalt.charAt(5)+dbSalt.charAt(4);
        return md5(str);
    }
    public static String inputPassToDBPass(String password,String salt) {
        String transPass = inputPassToTransPass(password);
        return transPassToDBPass(transPass,salt);
    }
    public static void main(String[] args) {
        System.out.println(inputPassToTransPass("123456"));
        System.out.println(transPassToDBPass("d3b1294a61a07da9b49b6e22b2cbd7f9","1a2b3c4d"));
        System.out.println(inputPassToDBPass("123456","1a2b3c4d"));
    }
}
